package org.stwy.lease.rent;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.rap.common.persistence.IBaseDAO;

/**
 * 租金收缴 DAO类
 */
/**
*版权信息 (c) RAP 保留所有权利.
*@author Rap.Codegen
*@Team RAP Team
*@Date 2015-4-25 12:31:24
*<p></p>
*
*@参与人：Rap.Codegen
*/
 
public interface RentDAO extends IBaseDAO<RentEntity, String> {
	@Query(" from RentEntity a where a.shouldPayDate<=?1 and a.hasPay=0 and a.status=1 order by a.shouldPayDate asc")
	List<RentEntity> findToPayRecords(Date curDate);

	@Query(" from RentEntity a where a.shouldPayDate= ("
			+ "select max(b.shouldPayDate) from RentEntity b where b.contract.uuid=?1"
			+ ") and a.contract.uuid=?1")
	RentEntity getlastRecordByContractId(String contractId);

	@Query(" from RentEntity a where a.shouldPayDate= ("
			+ "select max(b.shouldPayDate) from RentEntity b where b.contract.uuid=?1 and b.hasPay=0"
			+ ") and a.contract.uuid=?1")
	RentEntity getlastToPayRecordByContractId(String contractId);

	@Query(" from RentEntity a where a.shouldPayDate= ("
			+ "select max(b.shouldPayDate) from RentEntity b where b.contract.uuid=?1 and b.hasPay=1"
			+ ") and a.contract.uuid=?1")
	RentEntity getlastHasPayRecordByContractId(String contractId);
	
}
